package com.tywj.panda.customer.common.view.base

import androidx.fragment.app.FragmentManager
import androidx.lifecycle.LifecycleOwner
import com.tywj.panda.customer.common.view.dialog.LoadingDialog
import com.tywj.lib.businessweak.view.IBaseView
import com.tywj.lib.core.common.util.ToastUtil

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/05/08
 *     desc   :
 *     version: 1.0
 * </pre>
 */
class BaseViewImpl(
    private val fragmentManager: FragmentManager,
    private val lifecycleOwner: LifecycleOwner
) : IBaseView {

    private val loadingDialog by lazy {
        fragmentManager.findFragmentByTag(LoadingDialog.TAG) as? LoadingDialog ?: LoadingDialog()
    }

    override fun shortToast(msg: CharSequence) {
        ToastUtil.shortToast(msg)
    }

    override fun shortToast(id: Int) {
        ToastUtil.shortToast(id)
    }

    override fun longToast(msg: CharSequence) {
        ToastUtil.longToast(msg)
    }

    override fun longToast(id: Int) {
        ToastUtil.longToast(id)
    }

    override fun showLoadingDialog(msg: String) {
        loadingDialog.showDialog(fragmentManager)
    }

    override fun showLoadingDialog(id: Int) {
        loadingDialog.showDialog(fragmentManager)
    }

    override fun dismissLoadingDialog() {
        loadingDialog.dismissDialog()
    }

    override fun getLifecycleOwner(): LifecycleOwner {
        return lifecycleOwner
    }

    override fun getFragmentManagerInstance(): FragmentManager {
        return fragmentManager
    }
}